package connmobroute

import (
	"git.sr.ht/~mil/mobroute/src/apidb"
	"git.sr.ht/~mil/transito/utilfuncs"
)

func MobrouteExecuteDBStatusMDBIDs(csv string) ([]apidb.SourceStatus, error) {
	var (
		config    = apidb.Config{}
		mdbids, _ = utilfuncs.ParseCsvToInts(csv)
	)
	if len(mdbids) == 0 {
		// Note by default empty filter in mobsql sourceset filter passes
		// through entire / all sources - this is not really desirable on UI side
		return []apidb.SourceStatus{}, nil
	} else {
		return apidb.Status(apidb.SourcesetFilter{Mdbid: mdbids}, &config)
	}
}

func MobrouteExecuteDBStatusSearch(glob string) ([]apidb.SourceStatus, error) {
	var (
		config = apidb.Config{}
		filter = apidb.SourcesetFilter{
			Status: "active",
			Glob:   glob,
		}
	)
	return apidb.Status(filter, &config)
}
